#ifndef CLUSNET_NET_UDPSESSION_H
#define CLUSNET_NET_UDPSESSION_H

#include <memory>
#include <deque>
#include <boost/asio.hpp>
#include "Callbacks.h"
#include <clusnet/base/Logging.h>

namespace clusnet
{
namespace net
{

#define maxsize 65535
class UdpSession final : public std::enable_shared_from_this<UdpSession>
{
    public:
        UdpSession(boost::asio::io_context& io, boost::asio::io_context::strand& strand, boost::asio::ip::udp::socket& socket, boost::asio::ip::udp::endpoint const& remoteEndpoint, UdpWriteCompleteCallback const&);
        ~UdpSession();
        UdpSession(UdpSession const&) = delete;
        UdpSession& operator= (UdpSession const&) = delete;

    public:
        boost::asio::ip::udp::endpoint  localEndpoint() const { return socket_.local_endpoint(); }
        boost::asio::ip::udp::endpoint  remoteEndpoint() const { return remoteEndpoint_; }
        void safeAsyncWrite(UdpDataPacketPtr const&);

    private:
        void asyncWrite();

    private:
        boost::asio::io_context&            io_;
        boost::asio::io_context::strand&    strand_;
        boost::asio::ip::udp::socket&       socket_;
        boost::asio::ip::udp::endpoint      remoteEndpoint_;
        
        std::deque<UdpDataPacketPtr>        sendMsgs_;

        UdpWriteCompleteCallback            writeCallback_;
};
}
}

#endif 
